/******************************************************************************
 * * inter_common_ui_interface.h - interface for create common UI
 *
 * *(C) Copyright 2019 ASR International Ltd.
 * * All Rights Reserved
 * ******************************************************************************/
#ifndef INTER_COMMON_UI_INTERFACE_H_
#define INTER_COMMON_UI_INTERFACE_H_

#ifdef __cplusplus
extern "C" {
#endif

/*********************
*      INCLUDES
*********************/
#include "ui_type.h"
#include "ui_textid.h"
#include "lvgl.h"
#include "app_adaptor_interface.h"
#ifndef LV_I18N_ENABLE
#include "../framework/language/lv_lang.h"
#else
#include "../framework/language/lv_i18n/lv_i18n_lang.h"
#endif
#include "../framework/common/lv_theme_simple.h"
#include "ui_phone_res.h"

/**********************
*      MACROS
**********************/
#ifndef BUILD_IN_PC_SIMULATOR
  #define FP_HOR_RES                    LV_HOR_RES
  #define FP_VER_RES                    LV_VER_RES
#else
  #ifdef USE_LV_INTERPHONE_DEMO
    #define FP_HOR_RES                    (160)
    #define FP_VER_RES                    (128)
  #elif USE_LV_DEMO_128x64
    #define FP_HOR_RES                    (128)
    #define FP_VER_RES                    (64)
  #else
    #define FP_HOR_RES                    (240)
    #define FP_VER_RES                    (320)
  #endif
#endif

#ifdef USE_LV_INTERPHONE_DEMO
#define FP_STATUS_BAR_H               (FP_VER_RES / 6)
#define FP_TITLE_BAR_H                (FP_VER_RES / 7)
#else
#define FP_STATUS_BAR_H               (FP_VER_RES / 10)
#define FP_TITLE_BAR_H                (FP_VER_RES / 10)
#endif
#define FP_BUTTON_BAR_H               (FP_VER_RES / 10)
#define FP_BUTTON_BAR_W               (FP_HOR_RES / 3)
#define FP_WIN_H                      (FP_VER_RES - FP_STATUS_BAR_H)
#define FP_CONT_BAR_H                 (FP_VER_RES - FP_STATUS_BAR_H - FP_TITLE_BAR_H - \
                                       FP_BUTTON_BAR_H)
#define FP_NOTITLE_CONT_BAR_H         (FP_VER_RES - FP_STATUS_BAR_H - FP_BUTTON_BAR_H)
#define FP_MENU_ICON_W                (FP_HOR_RES / 4)

#define FP_CALULATOR_TA_MAX_LENGTH    (9)
#define FP_SCROLLBAR_WIDTH            (5)

#ifdef UI_COMMON_DUMMY
#define FP_PARENT                     UI_Common_Test_Scr()
#define FP_KEY_READ                   UI_Common_Test_Keyboard_Read
#else
#define FP_PARENT                     lv_scr_act()
#define FP_KEY_READ                   keypad_crane_evb_read
#endif

#define UI_MAX_YEAR_NUM               2037
#define UI_MIN_YEAR_NUM               1970

#define UI_MAX_CONT_BTN_NUM           4
#define UI_MAX_SEARCH_CONT_BTN_NUM    (UI_MAX_CONT_BTN_NUM - 2)

#define FP_INPUT_CONT_H               (50)
#define FP_INPUT_IME_SYMBOL_H         (30)
#define FP_INPUT_TA_H                 (30)
#define FP_SEARCH_LIST_H              (FP_CONT_BAR_H - FP_INPUT_CONT_H - FP_INPUT_TA_H - \
                                       FP_INPUT_IME_SYMBOL_H)

/* define struct of Base Object, begin */
typedef enum
{
    UI_ROLLER_TYPE_YEAR = 0x00,
    UI_ROLLER_TYPE_MONTH,
    UI_ROLLER_TYPE_DAY,
    UI_ROLLER_TYPE_HOUR,
    UI_ROLLER_TYPE_MINUTE,
    UI_ROLLER_TYPE_SECOND,
    UI_ROLLER_TYPE_MAX
} UI_ROLLER_TYPE;

/* Label */
typedef struct
{
    UINT16             TxtId;                       // in, Text ID,
    INT8               *SymbolId;                   // in, Symbol
    const VOID         *ImgSrc;                     // in, img src
    lv_font_t          *TxtFont;                    // in, text font, NULL for not present
    lv_label_align_t   TxtAlign;                    // in, text alignment
    lv_label_align_t   SymbolAlign;                 // in, image alignment
    lv_align_t         LabelAlign;                  // in, label align
    lv_obj_t           *Label;                      // out, pointer of created Label
    lv_obj_t           *Img;                        // out, pointer of created LabelImg
} UI_Label_Desc_t;

/* Button */
typedef struct
{
    UINT8         ButtonIndex;                      // Available only in List
    INT8          *BtnTxt;                          // in, Text
    UINT16        TxtId;                            // in, Text ID
    INT8          *SymbolId1;                       // in, Symbol
    INT8          *SymbolId2;                       // in, Symbol
    lv_obj_t      *Button;                          // out, pointer of created button
    lv_event_cb_t ReleaseFun;                       // call back for button release
    bool          Valid;                            // true:button is valid; false:button is invalid
} UI_Button_Desc_t;

/* Menu Button */
typedef struct
{
    VOID          *Icon;                            // in, pointer of APP icon
    lv_obj_t      *Button;                          // out, pointer of created button
    lv_event_cb_t ReleaseFun;                       // call back for button release
} UI_Menu_Button_Desc_t;

/* List */
typedef struct
{
    UINT8            Index;                         // Current Button
    UINT8            ListButtonCnt;                 // button count in list
    UI_Button_Desc_t *ButtonList;                   // Button pointer header
    lv_obj_t         *List;                         // out, pointer of created List
} UI_List_Desc_t;

/* Bar */
typedef struct
{
    UINT8      Range;                               // in, Max rang of the bar
    UINT8      Value;                               // in, current value of rang
    lv_align_t BarAlign;                            // in, Bar Align
    lv_obj_t   *Bar;                                // out, pointer of the bar
} UI_Bar_Desc_t;

/* Button Matrix */
typedef struct
{
    INT8          *BtnmTxt;                         // in, Button text
    lv_event_cb_t ReleaseFun;                       // call back for button release
    lv_obj_t      *ButtonMatrix;                    // out, pointer of created Button Matrix
} UI_Button_Matrix_Desc_t;

/* Text Aera */
typedef struct
{
    INT8             *TaTxt;                        // in, Text
    BOOL             TaCursorHide;                  // in, display or hide cursor
    lv_align_t       TaAlign;                       // in, Ta Align
    lv_obj_t         *TextArea;                     // out, pointer of created Text Area
} UI_Text_Area_Desc_t;

/* Image */
typedef struct
{
    VOID       *Img;                                    // in, Symble
    lv_align_t ImgAlign;                                // in, Img Align
} UI_Img_Desc_t;

/* Roller */
typedef struct
{
    UINT16         MidValue;
    lv_event_cb_t  SelAction;                       //
    lv_obj_t       *Roller;                         // out, pointer of created Roller
    UI_ROLLER_TYPE RollerType;                      // in, year/month/day/hour/min/sec..
} UI_Roller_Desc_t;

/* Calendar */
typedef VOID (* UI_Cale_Info_Cb)(lv_calendar_date_t *ShowedDate, INT8 Output[]);

typedef struct
{
    lv_calendar_date_t Today;                       // in, Date of Today
    UINT8              HighlitedDaysCnt;            // in, Count of Highlighted Days, Max value is 10
    lv_calendar_date_t *HighlihtedDays;             // in, phighlihted_days
    lv_calendar_date_t ShowedDate;
    UI_Cale_Info_Cb    ShowedDateInfoCb;            // in, callback to get Lunar(CH),WeekNum(En) for showed date
    lv_obj_t           *Calendar;                   // out, pointer of created Calendar
} UI_Calendar_Desc_t;

/* Container */
typedef struct
{
    lv_obj_t *Container;                            // out, pointer of created Container
} UI_Container_Desc_t;

/* Button Bar */
typedef struct
{
    UI_Button_Desc_t ButtonL;                      // Left button
    UI_Button_Desc_t ButtonM;                      // Middle button
    UI_Button_Desc_t ButtonR;                      // Right button
} UI_Button_Bar_Desc_t;
typedef struct
{
    BOOL     State;
    lv_obj_t *sw;
} UI_Sw_Desc_t;

/* Container Base */
typedef enum
{
    UI_BASE_OBJ_NULL = 0,
    UI_BASE_OBJ_LABEL,
    UI_BASE_OBJ_BAR,
    UI_BASE_OBJ_IMG,
    UI_BASE_OBJ_TA,
    UI_BASE_OBJ_SW,
    UI_BASE_OBJ_SW_ONE_ROW,                        // label and switch are in one row
} UI_BASE_OBJECT_TYPE;

typedef struct
{
    UI_Label_Desc_t     Label;                     // in, 1st Item in container
    UI_BASE_OBJECT_TYPE Choise;                    // in, Object type of 2nd Item in Container
    union
    {
        UI_Label_Desc_t     Label2;                // in, Label for 2nd Item
        UI_Bar_Desc_t       Bar;                   // in, Bar for 2nd Item
        UI_Img_Desc_t       Img;                   // in, Image for 2nd Item
        UI_Text_Area_Desc_t Ta;                    // in, Text Aera for 2nd Item
        UI_Sw_Desc_t        Sw;
    }           u;
    lv_event_cb_t ReleaseFunc;                     // in, Called when click KEY_OK
    lv_obj_t      *Button;                         // out, Pointer of listbtn
    BOOL          Valid;                           // true:item is valid; false:item is invalid
} UI_Container_Base_Desc_t;

/* Container List */
typedef struct
{
    UINT8                    ListContainerCnt;      // Container count in the list
    UINT8                    Index;                 // Container select index
    UI_Container_Base_Desc_t *ContainerList;        // Button pointer header
} UI_Container_List_Desc_t;

/* Container Time */
typedef struct
{
    UI_Roller_Desc_t Roller1;                       // Hour/Minute Option Roller
    UI_Roller_Desc_t Roller2;                       // Minute/Second Option Roller
} UI_Container_Time_Desc_t;

/* Container Date */
typedef struct
{
    UI_Roller_Desc_t RollerDay;                     // Day Option Roller
    UI_Roller_Desc_t RollerMonth;                   // Month Option Roller
    UI_Roller_Desc_t RollerYear;                    // Year Option Roller
} UI_Container_Date_Desc_t;

/* Container Label Bar */
typedef struct
{
    UI_Label_Desc_t Label;                          // in, Label in container
    UI_Bar_Desc_t   Bar;                            // in, Bar in container
    lv_obj_t        *ContBar;                       // out, pointer of created Container
} UI_Container_Label_Bar_Desc_t;

/* Page Multi Button */
typedef struct
{
    UINT8                 ListButtonCnt;            // button count in list
    UI_Menu_Button_Desc_t *ButtonList;              // Button pointer header
    lv_obj_t              *Page;                    // out, pointer of created Page
    UINT8                 FocusOnBtn;               // index of button which focus is on
} UI_Page_Multi_Button_Desc_t;

/* Container_Button_Scroll */
typedef struct
{
    UI_Button_Desc_t    ContButton[UI_MAX_SEARCH_CONT_BTN_NUM]; // in, Symbol or text
    UI_Container_Desc_t ContScrl;                               // out, Simulate scroll bar
    UINT16              Height;                                 // in, Scroll bar height
    UINT16              PosY;                                   // in, Scroll bar pos
    UINT8               Index;                                  // in, Focused button index
    lv_obj_t            *List;                                  // out,Pointer to a list
} UI_Container_Button_Scroll_Desc_t;

/* Container_Label_Ta */
typedef struct
{
    UI_Label_Desc_t     ContLabel;                  // in, Symbol or text, Top in Container
    UI_Text_Area_Desc_t ContTa;                     // in, Input text
} UI_Container_Label_Ta_Desc_t;

/* Button_Container_Ta */
typedef struct
{
    UI_Container_Button_Scroll_Desc_t ContButtonScrl;
    UI_Container_Label_Ta_Desc_t      ContLabelTa;
} UI_Button_Container_Ta_Desc_t;

/* Button_Container */
typedef struct
{
    UI_Button_Desc_t    ContButton[UI_MAX_CONT_BTN_NUM]; // in, Symbol or text
    UI_Container_Desc_t ContScrl;                        // out, Simulate scroll bar
    UINT16              Height;                          // in, Scroll bar height
    UINT16              PosY;                            // in,Scroll bar Pos
    UINT8               Index;                           // in,Focused button index
    lv_obj_t            *List;                           // out,Pointer to a list
} UI_Button_Container_Desc_t;

/* Label_Ta */
typedef struct
{
    UI_Label_Desc_t              ContLabel;         // in, Symbol or text, Top in Container
    UI_Container_Label_Ta_Desc_t ContLabelTa;
} UI_Label_Ta_Desc_t;

/* Container Label */
typedef struct
{
    UI_Label_Desc_t ContLabelU;                     // in, Symbol or text, Top in Container
    UI_Label_Desc_t ContLabelD;                     // in, Symbol or text, Button in Container
    UI_Label_Desc_t ContLabelL;                     // in, Symbol or text, Left in Container
    UI_Label_Desc_t ContLabelR;                     // in, Symbol or text, Right in Container
} UI_Container_Label_Desc_t;
/* define struct of Base Object, end */

/* define Key callback function, begin */
typedef enum
{
    KEY_PRESSED = 0,
    KEY_RELEASED,
    KEY_LONGPRESS
} UI_KEY_STATUS;

typedef enum
{
    KEY_0 = 48,
    KEY_1,
    KEY_2,
    KEY_3,
    KEY_4,
    KEY_5,
    KEY_6,
    KEY_7,
    KEY_8,
    KEY_9,
    KEY_ASTERISK  = '*',   // *
    KEY_HASH      = '#',   // #
    KEY_OK        = LV_KEY_ENTER,
    KEY_SOFTLEFT  = LV_KEY_SL,
    KEY_SOFTRIGHT = LV_KEY_BACKSPACE,
    KEY_DIAL      = LV_KEY_DIAL,
    KEY_END       = LV_KEY_END,
    KEY_UP        = LV_KEY_UP,
    KEY_DOWN      = LV_KEY_DOWN,
    KEY_LEFT      = LV_KEY_LEFT,
    KEY_RIGHT     = LV_KEY_RIGHT,
} UI_KEY_VALUE;

// if still want to use the default signal func ,return 0,or return Non-0.
typedef UINT8 UI_Handle_Key_CallBack (lv_obj_t *obj, UI_KEY_STATUS key_sta, UI_KEY_VALUE key_val);
typedef VOID UI_List_Btn_Selected_CallBack (lv_obj_t *list, lv_obj_t *btn);

/* define Key callback function, end */

/* define struct of Common Interface, begin */
/* Normal_List_Only */
typedef struct
{
    UI_Label_Desc_t        TitleBar;                // Title Bar
    UI_List_Desc_t         List;                    // Content Bar
    UI_Button_Bar_Desc_t   BtnBar;                  // Button Bar
    UI_Handle_Key_CallBack *KeyFunc;                // KeyFunc
} UI_Normal_List_Only_Desc_t;

/* Normal_Ta_Only */
typedef struct
{
    UI_Label_Desc_t        TitleBar;                // Title Bar
    UI_Text_Area_Desc_t    ContTa;                  // Content Bar
    UI_Button_Bar_Desc_t   ButtonBar;               // Button Bar
    UI_Handle_Key_CallBack *KeyFunc;                // KeyFunc
} UI_Normal_Ta_Only_Desc_t;

/* Normal_Label_Only */
typedef struct
{
    UI_Label_Desc_t        TitleBar;                // Title Bar
    UI_Label_Desc_t        ContLabel;               // Content Bar
    UI_Button_Bar_Desc_t   ButtonBar;               // Button Bar
    UI_Handle_Key_CallBack *KeyFunc;                // KeyFunc
} UI_Normal_Label_Only_Desc_t;

/* Normal_Container_List */
typedef struct
{
    UI_Label_Desc_t          TitleBar;              // Title Bar
    UI_Container_List_Desc_t ContList;
    lv_obj_t                 *List;                 // out, pointer of created list
    UI_Button_Bar_Desc_t     ButtonBar;             // Button Bar
    UI_Handle_Key_CallBack   *KeyFunc;              // KeyFunc
    lv_coord_t               scrl_y;
} UI_Normal_Container_List_Desc_t;

/* Normal_Time */
typedef struct
{
    UI_Label_Desc_t          TitleBar;              // Title Bar
    UI_Container_Time_Desc_t ContTime;              // Content Bar
    UI_Button_Bar_Desc_t     ButtonBar;             // Button Bar
    UI_Handle_Key_CallBack   *KeyFunc;              // KeyFunc
} UI_Normal_Time_Desc_t;

/* Normal_Date */
typedef struct
{
    UI_Label_Desc_t          TitleBar;              // Title Bar
    UI_Container_Date_Desc_t ContDate;              // Content Bar
    UI_Button_Bar_Desc_t     ButtonBar;             // Button Bar
    UI_Handle_Key_CallBack   *KeyFunc;              // KeyFunc
} UI_Normal_Date_Desc_t;

/* Normal_Contact_Search_Button */
typedef struct
{
    UI_Label_Desc_t               TitleBar;          // Title Bar
    UI_Button_Container_Ta_Desc_t ButtonContainerTa; // Content Bar
    UI_Button_Bar_Desc_t          ButtonBar;         // Button Bar
    UI_Handle_Key_CallBack        *KeyFunc;          // KeyFunc
} UI_Normal_Contact_Search_Button_Desc_t;

/* Normal_Button_Container */
typedef struct
{
    UI_Label_Desc_t            TitleBar;            // Title Bar
    UI_Label_Desc_t            Label;               // If no contact, show this label
    UI_Button_Container_Desc_t ButtonContainer;     // Content Bar
    UI_Button_Bar_Desc_t       ButtonBar;           // Button Bar
    UI_Handle_Key_CallBack     *KeyFunc;            // KeyFunc
} UI_Normal_Button_Container_Desc_t;

/* Normal_Contact_Search_Label */
typedef struct
{
    UI_Label_Desc_t        TitleBar;                // Title Bar
    UI_Label_Ta_Desc_t     LabelTa;                 // Content Bar
    UI_Button_Bar_Desc_t   ButtonBar;               // Button Bar
    UI_Handle_Key_CallBack *KeyFunc;                // KeyFunc
} UI_Normal_Contact_Search_Label_Desc_t;

/* Normal_Alarm */
typedef struct
{
    UI_Label_Desc_t        TitleBar;                // Title Bar
    UI_Label_Desc_t        AnimLabel;               // Anim Label
    UI_Button_Bar_Desc_t   ButtonBar;               // Button Bar
    UI_Handle_Key_CallBack *KeyFunc;                // KeyFunc
    VOID                   *Dsc;
} UI_Normal_Alarm_Desc_t;

/* Normal_Reminder */
typedef struct
{
    UI_Label_Desc_t        TitleLabelL;             // in, Text, Left in the Title Bar
    UI_Label_Desc_t        TitleLabelR;             // in, Text, Right in the Title Bar
    UI_Label_Desc_t        ContLabel;               // in, Text, Content Bar
    UI_Button_Bar_Desc_t   ButtonCont;              // Button Bar
    UI_Handle_Key_CallBack *KeyFunc;                // KeyFunc
} UI_Normal_Reminder_Desc_t;

/* Normal_Switch_Off */
typedef struct
{
    UI_Container_Label_Bar_Desc_t ContBar;
    UI_Button_Desc_t              Button;           // in, button in Content Bar
    UI_Button_Bar_Desc_t          ButtonCont;       // Button Bar
    UI_Handle_Key_CallBack        *KeyFunc;         // KeyFunc
} UI_Normal_Switch_Off_Desc_t;

/* Normal_Menu */
typedef struct
{
    UI_Label_Desc_t             TitleBar;           // Title Bar
    UI_Page_Multi_Button_Desc_t PageMultiButton;    // Content Bar
    UI_Button_Bar_Desc_t        ButtonBar;          // Button Bar
    UI_Handle_Key_CallBack      *KeyFunc;           // KeyFunc
} UI_Normal_Menu_Desc_t;

/* Desktop_Unlock */
typedef struct
{
    VOID                   *Wall_Paper_Img;         // in
    UI_Label_Desc_t        ContLabel[2];            // in, Symbol or text
    UI_Button_Bar_Desc_t   ButtonBar;               // Button Bar
    UI_Handle_Key_CallBack *KeyFunc;                // KeyFunc
} UI_Desktop_Unlock_Desc_t;

/* Status */
typedef struct
{
    UI_Label_Desc_t        ContLabel;
    UI_Img_Desc_t          ContImg;
    lv_align_t             ContLabelAlign;          // Label alignment,Left or Up
    lv_align_t             ContImgAlign;            // Image alignment, Right or Down
    UI_Handle_Key_CallBack *KeyFunc;                // KeyFunc
} UI_Status_Desc_t;

/* Status_Label */
typedef struct
{
    UI_Label_Desc_t        ContLabel[2];            // in, Symbol or text
    lv_align_t             ContLabelAlign[2];       // Label alignment,Left or Up
    UI_Handle_Key_CallBack *KeyFunc;                // KeyFunc
} UI_Status_Label_Desc_t;

/* Normal_NoTitle */
typedef struct
{
    UI_Status_Desc_t       ContenCont;              // Content Bar
    UI_Button_Bar_Desc_t   ButtonBar;               // Button Bar
    UI_Handle_Key_CallBack *KeyFunc;                // KeyFunc
} UI_Normal_NoTitle_Desc_t;

/* Normal_NoTitle_Label_Ta */
typedef struct
{
    UI_Label_Desc_t        ContLabelTl;             // in, Symbol or text, Top Left
    UI_Label_Desc_t        ContLabelTr;             // in, Text, Top Right
    UI_Label_Desc_t        ContLabel;               // in, Text, Under ContLabelTl, half of Content Bar
    UI_Text_Area_Desc_t    ContTa;
    UI_Button_Bar_Desc_t   ButtonCont;              // Button Bar
    UI_Handle_Key_CallBack *KeyFunc;                // KeyFunc
} UI_Normal_NoTitle_Label_Ta_Desc_t;

/* Normal_NoTitle_Ta */
typedef struct
{
    UI_Label_Desc_t        ContLabelTl;             // in, Symbol or text, Top Left
    UI_Label_Desc_t        ContLabelTr;             // in, Text, Top Right
    UI_Text_Area_Desc_t    ContTa;
    UI_Button_Bar_Desc_t   ButtonBar;               // Button Bar
    UI_Handle_Key_CallBack *KeyFunc;                // KeyFunc
} UI_Normal_NoTitle_Ta_Desc_t;

/* Normal_Sms_Insert_Symbol */
typedef struct
{
    UI_Label_Desc_t         ContLabel;              // in, Symbol or text, Top Left
    UI_Button_Matrix_Desc_t ContBtnm;
    UI_Button_Bar_Desc_t    ButtonBar;              // Button Bar
    UI_Handle_Key_CallBack  *KeyFunc;               // KeyFunc
} UI_Normal_Sms_Insert_Symbol_Desc_t;

/* Normal_Calculator */
typedef struct
{
    UI_Label_Desc_t           FactorLabel1;
    UI_Label_Desc_t           FactorLabel2;
    UI_Label_Desc_t           SymbolLabel1;
    UI_Label_Desc_t           SymbolLabel2;
    UI_Text_Area_Desc_t       ContTa;
    UI_Container_Label_Desc_t ContLabel;
    UI_Button_Bar_Desc_t      ButtonBar;            // Button Bar
    UI_Handle_Key_CallBack    *KeyFunc;             // KeyFunc
} UI_Normal_Calculator_Desc_t;

/* Normal_Reminder_Alarm */
typedef struct
{
    UI_Img_Desc_t          ContImg;
    UI_Label_Desc_t        ContLabelR;
    UI_Label_Desc_t        ContLabelD;
    UI_Button_Bar_Desc_t   ButtonBar;               // Button Bar
    UI_Handle_Key_CallBack *KeyFunc;                // KeyFunc
} UI_Normal_Reminder_Alarm_Desc_t;

/* Normal_NoTitle_Labels_Bar */
typedef struct
{
    UI_Label_Desc_t        ContLabel[4];
    UI_Bar_Desc_t          Bar;
    UI_Button_Bar_Desc_t   ButtonBar;               // Button Bar
    UI_Handle_Key_CallBack *KeyFunc;                // KeyFunc
} UI_Normal_NoTitle_Labels_Bar_Desc_t;

/* FullScreen_Label_Only */
typedef struct
{
    UI_Label_Desc_t        ContLabel;
    UI_Handle_Key_CallBack *KeyFunc;                                    // KeyFunc
} UI_FullScreen_Label_Only_Desc_t;

/* FullScreen_Label */
typedef struct
{
    UI_Label_Desc_t        BatteryLabel;            // in, Base Label ,need return pionter of created Label
    UI_Label_Desc_t        ChargeLabel;             // in, Embed in Base Label
    UI_Handle_Key_CallBack *KeyFunc;                // KeyFunc
} UI_FullScreen_Label_Desc_t;

/* Calendar */
typedef struct
{
    UI_Calendar_Desc_t     Calendar;
    UI_Button_Bar_Desc_t   ButtonBar;               // Button Bar
    UI_Handle_Key_CallBack *KeyFunc;                // KeyFunc
} UI_Calendar_Only_Desc_t;

/* Desktop */
typedef struct
{
    VOID                   *Wall_Paper_Img;         // in
    UI_Label_Desc_t        Oper_Label[2];           // in, Symbol and text
    UI_Label_Desc_t        ContLabel[3];            // in, Text
    UI_Button_Bar_Desc_t   ButtonBar;               // Button Bar
    lv_obj_t               *Img;                    // out, pointer to wallpaper obj
    UI_Handle_Key_CallBack *KeyFunc;                // KeyFunc
} UI_Desktop_Desc_t;

/* Status_Bar */
typedef struct
{
    UI_Img_Desc_t          SimImg[2];               // in, Symbol, Left in Status Bar
    UI_Container_Desc_t    StatusCont;              // in, Symbol, Middle in Status Bar
    UI_Label_Desc_t        BatteryLabel;            // in, Symbol, Right in Status Bar
} UI_Status_Bar_Desc_t;

/* FullScreen_Key_Guard */
typedef struct
{
    UI_Label_Desc_t        TimeLabel;               // in, time
    UI_Label_Desc_t        DateLabel;               // in, date
    UI_Img_Desc_t          SymbolImg[2];            // in, symbol
    UI_Handle_Key_CallBack *KeyFunc;                // KeyFunc
} UI_FullScreen_Key_Guard_Desc_t;

typedef struct
{
    UI_Label_Desc_t        Oper_Label[2];               // in, Symbol and text
    UI_Label_Desc_t        ContLabel;                   // in, missed call or sms
    UI_Button_Bar_Desc_t   ButtonBar;                   // Button Bar
    UI_Handle_Key_CallBack *KeyFunc;                    // KeyFunc
} UI_Desktop_Prompt_Desc_t;

typedef struct
{
    UI_Label_Desc_t        Oper_Label[2];                    // in, Symbol and text
    UI_Text_Area_Desc_t    PadTa;
    UI_Button_Bar_Desc_t   ButtonBar;                        // Button Bar
    UI_Handle_Key_CallBack *KeyFunc;                         // KeyFunc
} UI_DialPad_Desc_t;

typedef struct
{
    lv_obj_t               *Img;
    VOID                   *ImgSrc;
    UI_Button_Desc_t       Btn;
    UI_Handle_Key_CallBack *KeyFunc;                         // KeyFunc
    lv_task_t              *PreviewTask;
} UI_Camera_Desc_t;

typedef struct
{
    const VOID             *ImgSrc;         // in
}UI_FullScreen_Img_Desc_t;

enum
{
    UI_WLAN_BTN_TYPE_ACT = 0,
    UI_WLAN_BTN_TYPE_OPENING,
    UI_WLAN_BTN_TYPE_SAVED,
    UI_WLAN_BTN_TYPE_OPEN_FAIL,
    UI_WLAN_BTN_TYPE_SCAN_LIST,
    UI_WLAN_BTN_TYPE_REFRESH,
    UI_WLAN_BTN_TYPE_REFRESHING,
};
typedef UINT8 UI_WLAN_BTN_TYPE_T;

typedef struct
{
    lv_obj_t           *Par;
    lv_obj_t           *Btn;
    UI_WLAN_BTN_TYPE_T Type;
    INT8               *Ssid;        // ssid for ap, not free
    BOOL               IsSecurity;
    VOID               *ImgSrc1;     // lock picture for ap
    VOID               *ImgSrc2;     // signal picture for ap, refresh picture for opening ap or scanning
    lv_event_cb_t      BtnFunc;
    UINT32             ApLen;        // the length of data for ap
    VOID               *Ap;          // the pointer of ap;
    lv_anim_ready_cb_t AnimFp;       // refresh animation function for opening ap or scanning
} UI_Wlan_Btn_Desc_t;

typedef struct
{
    BOOL          State;
    lv_obj_t      *Sw;
    lv_event_cb_t BtnFunc;
} UI_Wlan_Sw_Desc_t;

typedef struct
{
    UI_Label_Desc_t        TitleBar;        // Title Bar
    UI_Wlan_Sw_Desc_t      Sw;
    lv_obj_t               *List;
    lv_obj_t               *RefreshImg;
    UI_Button_Bar_Desc_t   BtnBar;          // Button Bar
    UI_Handle_Key_CallBack *KeyFunc;        // KeyFunc
    UINT8                  Index;
    UINT8                  Total;
} UI_Wlan_Desc_t;

typedef struct
{
    UI_Label_Desc_t     Label;                      // in, 1st Item in container
    UI_BASE_OBJECT_TYPE Choise;                     // in, Object type of 2nd Item in Container
                                                    // valid type: NULL/Label/Ta/Switch
    union
    {
        UINT8               LabelNum;               // in, for UI_BASE_OBJ_LABEL
        UI_Text_Area_Desc_t Ta;                     // in, for UI_BASE_OBJ_TA
        UI_Wlan_Sw_Desc_t   Sw;                     // in, for UI_BASE_OBJ_SW
    } u;
    lv_event_cb_t RelFunc;                          // in, Called when click KEY_OK
    lv_obj_t *Btn;
} UI_Wlan_Btn_Base_Desc_t;

typedef struct
{
    UI_Label_Desc_t         TitleBar;                // Title Bar
    UINT8                   Index;                   // In, current button
    UINT8                   BtnCnt;                  // In, button count in list
    UI_Wlan_Btn_Base_Desc_t *BtnList;                // In, button pointer header
    lv_obj_t                *List;                   // Out, pointer of created List
    UI_Button_Bar_Desc_t    BtnBar;                  // In, Button Bar
    UI_Handle_Key_CallBack  *KeyFunc;                // In, KeyFunc
    VOID                    *Param;                  // In, pointer
} UI_Wlan_List_Desc_t;

/* define struct of Common Interface, end */

/* define Common Interface, begin */
/**
 * Set user_num for obj
 * param (in) Obj: lv_obj_t *
 * param (in) User_Num: UINT32
 * return  VOID
 */
extern VOID UI_Set_User_Num(lv_obj_t * Obj, UINT32 User_Num);

/**
 * Set user_ptr for obj
 * param (in) Obj: lv_obj_t *
 * param (in) User_Ptr: VOID *
 * return  VOID
 */
extern VOID UI_Set_User_Ptr(lv_obj_t * Obj, VOID * User_Ptr);

/**
 * Get user_num for obj
 * param (in) Obj: lv_obj_t *
 * return  UINT32
 */
extern UINT32 UI_Get_User_Num(lv_obj_t * Obj);

/**
 * Get user_ptr for obj
 * param (in) Obj: lv_obj_t *
 * return  VOID *
 */
extern VOID * UI_Get_User_Ptr(lv_obj_t * Obj);

/**
 * Creat Normal_List_Only
 * param (in) NormalLstOnlyDesc: UI_Normal_List_Only_Desc_t*
 * return  VOID
 */
extern VOID UI_Normal_List_Only_Create(VOID *NormalLstOnlyDesc);

/**
 * Creat Normal_Ta_Only
 * param (in) NormalTaOnlyDesc: UI_Normal_Ta_Only_Desc_t*
 * return  VOID
 */
extern VOID UI_Normal_Ta_Only_Create(VOID *NormalTaOnlyDesc);

/**
 * Creat Normal_Label_Only
 * param (in) NormalLblOnlyDesc: UI_Normal_Label_Only_Desc_t*
 * return  VOID
 */
extern VOID UI_Normal_Label_Only_Create(VOID *NormalLblOnlyDesc);

/**
 * Creat Normal_Container_List
 * param (in) NormalContLstDesc: UI_Normal_Container_List_Desc_t*
 * return  VOID
 */
extern VOID UI_Normal_Container_List_Create(VOID *NormalContLstDesc);

/**
 * Creat Normal_Time
 * param (in) NormalTimeDesc: UI_Normal_Time_Desc_t*
 * return  VOID
 */
extern VOID UI_Normal_Time_Create(VOID *NormalTimeDesc);

/**
 * Creat Normal_Time
 * param (in) NormalTimeDesc: UI_Normal_Time_Desc_t*
 * return  VOID
 */
extern VOID UI_Normal_Min_And_Sec_Create(VOID *NormalTimeDesc);

/**
 * Creat Normal_Date
 * param (in) NormalDateDesc: UI_Normal_Date_Desc_t*
 * return  VOID
 */
extern VOID UI_Normal_Date_Create(VOID *NormalDateDesc);

/**
 * Creat Normal_Contact_Search_Button
 * param (in) NormalContSrhBtnDesc: UI_Normal_Contact_Search_Button_Desc_t*
 * return  VOID
 */
extern VOID UI_Normal_Contact_Search_Button_Create(VOID *NormalContSrhBtnDesc);

/**
 * Creat Normal_Button_Container
 * param (in) NormalBtnContDesc: UI_Normal_Button_Container_Desc_t*
 * return  VOID
 */
extern VOID UI_Normal_Button_Container_Create(VOID *NormalBtnContDesc);

/**
 * Creat UI_Normal_Contact_Search_Label
 * param (in) NormalContSrhLblDesc: UI_Normal_Contact_Search_Label_Desc_t*
 * return  VOID
 */
extern VOID UI_Normal_Contact_Search_Label_Create(VOID *NormalContSrhLblDesc);

/**
 * Creat Normal_Alarm
 * param (in) NormalAlarmDesc: UI_Normal_Alarm_Desc_t*
 * return  VOID
 */
extern VOID UI_Normal_Alarm_Create(VOID *NormalAlarmDesc);

/**
 * Creat Normal_Reminder
 * param (in) NormalReminderDesc: UI_Normal_Reminder_Desc_t*
 * return  VOID
 */
extern VOID UI_Normal_Reminder_Create(VOID *NormalReminderDesc);

/**
 * Creat Normal_Switch_Off
 * param (in) NormalSwitchOffDesc: UI_Normal_Switch_Off_Desc_t*
 * return  VOID
 */
extern VOID UI_Normal_Switch_Off_Create(VOID *NormalSwitchOffDesc);

/**
 * Creat Normal_Menu
 * param (in) NormalMenuDesc: UI_Normal_Menu_Desc_t*
 * return  VOID
 */
extern VOID UI_Normal_Menu_Create(VOID *NormalMenuDesc);

/**
 * Creat Desktop_Unlock
 * param (in) DesktopUnlockDesc: UI_Desktop_Unlock_Desc_t*
 * return  VOID
 */
extern VOID UI_Desktop_Unlock_Create(VOID *DesktopUnlockDesc);

/**
 * Creat Status
 * param (in) StatusDesc: UI_Status_Desc_t*
 * return  VOID
 */
extern VOID UI_Status_Create(VOID *StatusDesc);

/**
 * Creat Status_Label
 * param (in) StatusLblDesc: UI_Status_Label_Desc_t*
 * return  VOID
 */
extern VOID UI_Status_Label_Create(VOID *StatusLblDesc);

/**
 * Creat Normal_NoTitle
 * param (in) NormalNoTitleDesc: UI_Normal_NoTitle_Desc_t*
 * return  VOID
 */
extern VOID UI_Normal_NoTitle_Create(VOID *NormalNoTitleDesc);

/**
 * Creat Normal_NoTitle_Label_Ta
 * param (in) NormalNoTitleLblTaDesc: UI_Normal_NoTitle_Label_Ta_Desc_t*
 * return  VOID
 */
extern VOID UI_Normal_NoTitle_Label_Ta_Create(VOID *NormalNoTitleLblTaDesc);

/**
 * Creat Normal_NoTitle_Ta
 * param (in) NormalNoTitleTaDesc: UI_Normal_NoTitle_Ta_Desc_t*
 * return  VOID
 */
extern VOID UI_Normal_NoTitle_Ta_Create(VOID *NormalNoTitleTaDesc);

/**
 * Creat Normal_Sms_Insert_Symbol
 * param (in) NormalSmsInsertSymbolDesc: UI_Normal_Sms_Insert_Symbol_Desc_t*
 * return  VOID
 */
extern VOID UI_Normal_Sms_Insert_Symbol_Create(VOID *NormalSmsInsertSymbolDesc);

/**
 * Creat Normal_Calculator
 * param (in) NormalCalDesc: UI_Normal_Calculator_Desc_t*
 * return  VOID
 */
extern VOID UI_Normal_Calculator_Create(VOID *NormalCalDesc);

/**
 * Creat Normal_Reminder_Alarm
 * param (in) NormalReminderAlarmDesc: UI_Normal_Reminder_Alarm_Desc_t*
 * return  VOID
 */
extern VOID UI_Normal_Reminder_Alarm_Create(VOID *NormalReminderAlarmDesc);

/**
 * Creat Normal_NoTitle_Labels_Bar
 * param (in) NormalNoTitleLblsBarDesc: UI_Normal_NoTitle_Labels_Bar_Desc_t*
 * return  VOID
 */
extern VOID UI_Normal_NoTitle_Labels_Bar_Create(VOID *NormalNoTitleLblsBarDesc);

/**
 * Creat FullScreen_Label_Only
 * param (in) FullScrnLblOnlyDesc: UI_FullScreen_Label_Only_Desc_t*
 * return  VOID
 */
extern VOID UI_FullScreen_Label_Only_Create(VOID *FullScrnLblOnlyDesc);

/**
 * Creat FullScreen_Label
 * param (in) FullScrnLblDesc: UI_FullScreen_Label_Desc_t*
 * return  VOID
 */
extern VOID UI_FullScreen_Label_Create(VOID *FullScrnLblDesc);

/**
 * Creat Calendar
 * param (in) CalendarDesc: UI_Calendar_Only_Desc_t*
 * return  VOID
 */
extern VOID UI_Calendar_Create(VOID *CalendarDesc);

/**
 * Creat Desktop
 * param (in) DesktopDesc: UI_Desktop_Desc_t*
 * return  VOID
 */
extern VOID UI_Desktop_Create(VOID *DesktopDesc);

/**
 * Creat Status_Bar
 * param (in) StaBarDesc: UI_Status_Bar_Desc_t*
 * return  VOID
 */
extern VOID UI_Status_Bar_Create(UI_Status_Bar_Desc_t *StaBarDesc);

/**
 * Creat FullScreen_Key_Guard
 * param (in) FullScrnKeyGuardDesc: UI_FullScreen_Key_Guard_Desc_t*
 * return  VOID
 */
extern VOID UI_FullScreen_Key_Guard_Create(VOID *FullScrnKeyGuardDesc);

/**
 * Creat Missed call or sms prompting UI
 * param (in) DesktopPromptDesc: UI_Desktop_Prompt_Desc_t*
 * return  VOID
 */
extern VOID UI_Desktop_Prompt_Create(VOID *DesktopPromptDesc);

/**
 * Create DialPad UI
 * param (in) DialPadDesc: UI_DialPad_Desc_t*
 * return  VOID
 */
VOID UI_DialPad_Create(VOID *DialPadDesc);

/**
 * Create camera
 * param (in) CameraDesc: UI_Camera_Desc_t*
 * return  VOID
 */
VOID UI_Camera_Create(VOID *CameraDesc);

/**
 * Destroy All Objects of Current Window
 * param (in) VOID
 * return VOID
 */
extern VOID UI_Normal_Destroy(VOID);

/**
 * Get Current Window
 * param (in) VOID
 * return pointer to current win obj
 */
extern lv_obj_t *UI_Normal_Get_Current_Win(VOID);

/**
 * Get Current Focused Object
 * param (in) VOID
 * return pointer to current focused obj
 */
extern lv_obj_t *UI_Normal_Get_Current_FocusedObj(VOID);

/**
 * UI wakes up with key
 * param (in) VOID
 * return VOID
 */
extern VOID UI_Wake_Up_With_Key(VOID);

/**
 * UI common init
 * param (in) VOID
 * return VOID
 */
extern VOID UI_Normal_Common_init(VOID);

/**
 * Fill options for roller
 * param (in) MidValue: UINT16
 * param (in) MaxValue: UINT16
 * param (in) MinValue: UINT16
 * param (in) OptStrLen: UINT18, 2 for month/day/hour/minute/second, 4 for year
 * return INT8 *
 */
extern INT8 *UI_Normal_Fill_Roller_Options(UINT16 MidValue, UINT16 MaxValue, UINT16 MinValue,
    UINT8 OptStrLen);

/**
 * Play animation for opening ap or refreshing
 * param (in) Img: lv_obj_t *
 * param (in) Src: const VOID *
 * param (in) Fp: lv_anim_ready_cb_t
 * return  VOID
 */
extern VOID UI_Wlan_Play_Refreshing_Anim(lv_obj_t *Img, const VOID *Src, lv_anim_ready_cb_t Fp);

/**
 * Add the button on the page of wlan ui
 * param (in) Desc: UI_Wlan_Btn_Desc_t*
 * return  VOID
 */
extern VOID UI_Wlan_Add_Btn(UI_Wlan_Btn_Desc_t *Desc);

/**
 * Creat Wlan
 * param (in) Param: VOID *
 * return  VOID
 */
extern VOID UI_Wlan_Create(VOID *Param);

/**
 * Common function to create ui with list structure
 * param (in) Param: VOID*
 * return  VOID
 */
extern VOID UI_Wlan_List_Create(VOID *Param);

/* define Common Interface, end */

/*define Common Test Interface,begin */

#if UI_COMMON_DUMMY != 0
extern bool UI_Common_Test_Keyboard_Read(lv_indev_drv_t * indev_drv, lv_indev_data_t *data);

extern lv_obj_t *UI_Common_Test_Scr(VOID);
extern VOID     UI_Common_Test_Main(VOID);

#endif

VOID Hal_Mem_Check_Start(VOID);
VOID Hal_Mem_Check_End(VOID);

/*for Interphone demo*/

typedef struct
{
    UI_Label_Desc_t        Label[6];                    // in, Symbol and text
    UI_Button_Desc_t       OperatorOpt;                 // Button Bar
    UI_Button_Desc_t       LoginBtn;
    UI_Handle_Key_CallBack *KeyFunc;                    // KeyFunc
} UI_Login_Desc_t;

typedef struct
{
    UI_Img_Desc_t          Img;
    UI_Label_Desc_t        Label1;
    UI_Label_Desc_t        Label2;
    UI_Button_Desc_t       QuitBtn;
    UI_Button_Desc_t       LogoutBtn;
    UI_Handle_Key_CallBack *KeyFunc;                             // KeyFunc
} UI_QuitOpt_Desc_t;

typedef struct
{
    UI_Label_Desc_t TimeLabel;
    UI_Label_Desc_t BatteryLabel;
    UI_Label_Desc_t SignalImg;
    UI_Label_Desc_t StanLabel;
    UI_Label_Desc_t VolumeLabel;
    UI_Label_Desc_t OnlineStateLabel;
} UI_Interphone_Status_Bar_Desc_t;

typedef struct
{
    UI_Label_Desc_t SignalLabel;             // in, Symbol, top Left
    UI_Label_Desc_t RatLabel;                // in, Txt, top middle
    UI_Label_Desc_t BatteryLabel;            // in, Symbol, top Right
    UI_Label_Desc_t DateLabel;               // in, Txt, bottom left
    UI_Label_Desc_t TimeLabel;               // in, Txt, bottom right
} UI_Demo_Desc_t;

typedef struct
{
    UI_Label_Desc_t        TitleLabel;
    UI_Label_Desc_t        TimeLabel;
    UI_Bar_Desc_t          ProgressSlider;
    UI_Bar_Desc_t          VolSlider;
    lv_obj_t               *Win;
    lv_task_t              *VolEndTask;
    UI_Button_Bar_Desc_t   BtnBar;
    UI_Handle_Key_CallBack *KeyFunc;                // KeyFunc
} UI_Audio_Player_Desc_t;

/**
 * Creat UI_Audio_Player_Desc_t
 * param (in) NormalNoTitleLblsBarDesc: UI_Audio_Player_Desc_t*
 * return  VOID
 */
extern VOID UI_Audio_NoTitle_Labels_Bar_Create(VOID *AudioNoTitleLblsBarDesc);

extern lv_obj_t * UI_slider_create(lv_obj_t * par_obj,lv_coord_t ver_offset,UI_Bar_Desc_t VolSlider);

/**
 * Create Interphone login UI
 * param (in) LoginDesc: UI_Login_Desc_t*
 * return  VOID
 */
extern VOID UI_Login_Create(VOID *LoginDesc);
extern VOID UI_GroupList_Create(VOID *GpoupListDesc);
extern VOID UI_Setting_Create(VOID *SettingDesc);
extern VOID UI_Quit_Option_Create(VOID *QuitOptDesc);
extern VOID UI_PowerOff_Create(VOID *PoweroffDesc);
extern lv_obj_t *UI_OperatorList_Create(lv_obj_t *Btn);
extern lv_obj_t *UI_TipMsg_Create(INT8 *MsgStr);
extern lv_obj_t *UI_Setting_Get_Sw_Cont(lv_obj_t *Btn);
extern VOID UI_Interphone_Test_Create(VOID *Param);

extern VOID UI_Login_Reset_FocusFunc(VOID);
extern lv_obj_t *UI_Volume_Slider_Create(UINT8 Volume);
extern VOID UI_Interphone_StatusBar_Create(VOID *StatusBarDesc);

extern VOID UI_Normal_Set_Btn_SeletedFunc_Clean(VOID);
extern lv_obj_t *UI_Create_NetSpeed_Label(lv_obj_t *Btn, FLOAT ULSpeed, FLOAT DLSpeed);
extern VOID UI_OperatorList_Action(lv_obj_t * Ddlist, lv_event_t Event);

extern VOID UI_FullScreen_Img_Create(VOID *FullScrnImgDesc);
extern lv_group_t * UI_Normal_Get_Group(VOID);

/*for Interphone demo end*/

extern VOID UI_Demo_128x64_Create(UI_Demo_Desc_t *Desc);

#ifdef __cplusplus
// }
#endif

#endif /*INTER_COMMON_UI_INTERFACE_H*/
